<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
   
      <el-form-item label="课程用书" prop="book">
        <el-input
          v-model="queryParams.book"
          placeholder="请输入课程用书"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zzxx:course:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="courseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="courseId" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="课程描述" align="center" prop="description" :show-overflow-tooltip="true"/>
      <el-table-column label="课程时间" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="课程用书" align="center" prop="book" />
      <el-table-column label="任课教师" align="center" prop="teacherId" />
      <el-table-column label="备注信息" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-video-play"
            @click="enterStudy(scope.row)"
          >进入学习</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="设置学习参数" :visible.sync="dialogVisible" width="500px" append-to-body >
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="章节" prop="field103">
          <el-select v-model="formData.field103" placeholder="请选择章节" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in field103Options" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="难度" prop="field104">
          <el-select v-model="formData.field104" placeholder="请选择难度" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in field104Options" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="题型" prop="field105">
          <el-select v-model="formData.field105" placeholder="请选择题型" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in field105Options" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCourse, getCourse, delCourse, addCourse, updateCourse } from "@/api/zzxx/course";

export default {
  name: "chooseCourse",
  data() {
    return {
      // 遮罩层
      loading: true,
      dialogVisible:false,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedZzxxAdminCourse: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 课程表表格数据
      courseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        time: null,
        book: null,
        createBy: null,
      },
      inheritAttrs: false,
      components: {},
      props: [],
      formData: {
        field103: 1,
        field104: undefined,
      },
      rules: {
        field103: [{
          required: true,
          message: '请选择章节',
          trigger: 'change'
        }],
        field104: [{
          required: true,
          message: '请选择难度',
          trigger: 'change'
        }],
        field105: [{
          required: true,
          message: '请选择题型',
          trigger: 'change'
        }],
      },
      field103Options: [{
        "label": "第一章",
        "value": 1
      }, {
        "label": "第一章",
        "value": 2
      }],
      field104Options: [{
        "label": "简单",
        "value": 1
      }, {
        "label": "中等",
        "value": 2
      }, {
        "label": "困难",
        "value": ""
      }],
      field105Options: [{
        "label": "选择题",
        "value": 1
      }, {
        "label": "填空题",
        "value": 2
      }, {
        "label": "判断题",
        "value": 3
      },
      {
        "label": "简答题",
        "value": 4
      }],
      // 表单参数
      form: {},
      // 表单校验
      //rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询课程表列表 */
    getList() {
      this.loading = true;
      listCourse(this.queryParams).then(response => {
        this.courseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //进入学习
    enterStudy(row){
      console.log("进入enterstudy方法")
      console.log(row)
      this.onOpen();
      this.open=true;
      console.log("dialogVisible "+this.dialogVisible)
    },
    onOpen() {
      this.dialogVisible=true;
      console.log("dialogVisible "+this.dialogVisible)
    },
    onClose() {
      this.$refs['elForm'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
      this.dialogVisible=false;
    },
    handleConfirm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        this.close()
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        courseId: null,
        name: null,
        description: null,
        time: null,
        book: null,
        teacherId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.zzxxAdminCourseList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>
